﻿#include <iostream>
#include "Queue.h"
#include "Stack.h"
using std::cout;
using std::endl;
using std::cin;
/*
a)	在队列中加入几个元素，用printQueue()打印队列内容，然后再从队列中取出这些元素，看是否正确
c)	测试取队列长度的函数getQueueLength()的正确性
*/
void testQueue()
{
	cout << "Queue test begin" << endl;

	Queue queue;
	cout << "len: " << queue.getQueueLength() << endl;

	for (int i = 0; i <= 3; i++)queue.push(i);
	cout << "len: " << queue.getQueueLength() << endl;
	queue.printQueue();

	cout << "front " << queue.front() << endl;
	for (int i = 0; i <= 3; i++)cout << "pop " << queue.pop() << endl;

	cout << "len: " << queue.getQueueLength() << endl;
	queue.printQueue();

	cout << "Queue test end" << endl;
	cout << endl;
}

/*
b)	在栈中加入几个元素，用printStack()打印栈的内容，然后再从栈中取出这些元素，看是否正确
d)	测试判断栈是否为空的函数empty()的正确性
*/
void testStack()
{
	cout << "Stack test begin" << endl;

	Stack stack;
	cout << "empty? " << stack.empty() << endl;

	for (int i = 0; i <= 3; i++)stack.push(i);
	cout << "empty: " << stack.empty() << endl;
	stack.printStack();

	cout << "front " << stack.top() << endl;
	for (int i = 0; i <= 3; i++)cout << "pop " << stack.pop() << endl;

	cout << "empty: " << stack.empty() << endl;
	stack.printStack();

	cout << "Stack test end" << endl;
	cout << endl;
}

void testLinkList()
{
	LinkList linkList;
	linkList.putHead(1);
	linkList.putTail(2);
	linkList.putTail(3);
	cout << linkList.GetAt(1) << endl;
	linkList.RemoveAt(2);
	linkList.GetAt(0) = 0;

	auto ptr = linkList.GetHead();
	while (ptr)
	{
		cout << ptr->data << endl;
		ptr = linkList.GetNext(ptr);
	}
}
int main()
{
	testQueue();
	testStack();

	testLinkList();
	return 0;
}